package com.jjb.www.ui.activity;

import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.shape.view.ShapeButton;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.ProblemFeedbackApi;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.http.model.HttpListData;
import com.jjb.www.ui.adapter.FeedbackAdapter;
import com.jjb.www.widget.CommonListRefreshView;
import com.jjb.www.widget.CommonRefreshView;

import java.util.List;

import okhttp3.Call;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/03/01
 *    desc   : 问题反馈
 */
public class ProblemFeedbackActivity extends AppActivity implements BaseAdapter.OnChildClickListener {
    private FeedbackAdapter mAdapter;
    private ShapeButton mBtnAdd;
    private CommonListRefreshView mRefreshView;



    @Override
    protected int getLayoutId() {
        return R.layout.activity_problem_feedback;
    }

    @Override
    protected void initView() {
        mBtnAdd = findViewById(R.id.btn_add);
        mRefreshView = findViewById(R.id.refreshView);
        mAdapter = new FeedbackAdapter(getContext());
        setOnClickListener(mBtnAdd);
        mAdapter.setOnChildClickListener(R.id.tv_look,this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        getList();
    }

    private void getList() {
        mRefreshView.setDataHelper(new CommonListRefreshView.DataHelper<ProblemFeedbackApi.Bean>() {
            @Override
            public AppAdapter<ProblemFeedbackApi.Bean> getAdapter() {
                return mAdapter;
            }

            @Override
            public void loadData(int p, HttpCallback<HttpList<ProblemFeedbackApi.Bean>> callback) {
                EasyHttp.get(ProblemFeedbackActivity.this)
                        .api(new ProblemFeedbackApi()
                                .setPage(p)
                                .setPageSize(mAdapter.getSize())
                        ).request(new HttpCallback<HttpList<ProblemFeedbackApi.Bean>>(ProblemFeedbackActivity.this) {

                    @Override
                    public void onStart(Call call) {

                    }

                    @Override
                    public void onSucceed(HttpList<ProblemFeedbackApi.Bean> result) {
                        callback.onSucceed(result);

                    }

                    @Override
                    public void onFail(Exception e) {
                        super.onFail(e);
                        callback.onFail(e);
                    }

                    @Override
                    public void onEnd(Call call) {
                        super.onEnd(call);
                        callback.onEnd(call);
                    }
                });
            }

            @Override
            public void onRefreshSuccess(List<ProblemFeedbackApi.Bean> list, int listCount) {

            }

            @Override
            public void onRefreshFailure() {

            }

            @Override
            public void onLoadMoreSuccess(List<ProblemFeedbackApi.Bean> loadItemList, int loadItemCount) {

            }

            @Override
            public void onLoadMoreFailure() {

            }
        });
        mRefreshView.initData();
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        if (view==mBtnAdd){
            Intent intent = new Intent();
            intent.putExtra("fromType","add");
            intent.setClass(getContext(),ReplyActivity.class);
            startActivity(intent);
        }
    }

    @Override
    public void onChildClick(RecyclerView recyclerView, View childView, int position) {
        if (childView.getId()==R.id.tv_look){
            Intent intent = new Intent();
            intent.putExtra("id",mAdapter.getItem(position).getId()+"");
            intent.setClass(getContext(),FeedbackDetailsActivity.class);
            startActivity(intent);
        }
    }
}